package com.magenta.maxoptra.gis.coding;

import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AddressQueryParser {

	private final String queryString;
	private Matcher regionMatcher;
	private Matcher keywordsMatcher;

	private final static Pattern REGION = Pattern.compile("(.*);.*");
	private final static Pattern KEYWORDS = Pattern.compile(".*;(.*)");

	public AddressQueryParser(String queryString) {
		this.queryString = queryString;
		regionMatcher = REGION.matcher(queryString);
		regionMatcher.matches();
		keywordsMatcher = KEYWORDS.matcher(queryString);
		keywordsMatcher.matches();
	}

	public String getRegion() {
		if (regionMatcher.groupCount() > 0) {
			return regionMatcher.group();
		}
		return null;
	}

	public List<String> getKeywords() {
		if (keywordsMatcher.groupCount() > 0) {
			return Collections.singletonList(keywordsMatcher.group());
		}
		return null;
	}

}
